package com.ideal.manage.esms.controller.diagnostic;

import com.ideal.manage.esms.bean.DTO.PageDto;
import com.ideal.manage.esms.bean.diagnostic.Diagnostic;
import com.ideal.manage.esms.bean.diagnostic.Parameters;
import com.ideal.manage.esms.bean.diagnostic.Process;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("diagnostic")
public class DiagnosticController {

    /**
     * 诊断列表请求
     *
     * @param model
     */
    @RequestMapping("diagnostic_list")
    public void diagnosticList(Model model) {

    }

    /**
     * 这段列表数据请求
     *
     * @param pageNum
     * @param request
     * @return
     */
    @RequestMapping("diagnostic_data")
    @ResponseBody
    public PageDto diagnosticData(int pageNum, HttpServletRequest request) {

        PageDto pageDto = new PageDto();
        pageDto.setTotal(2L);

        List<Diagnostic> diagnostics = new ArrayList<>();
        Diagnostic diagnostic1 = new Diagnostic();
        diagnostic1.setAlarmStatus("1");
        diagnostic1.setThresholdStatus("2");
        diagnostic1.setDiagnosticTime(new Date());
        diagnostic1.setDiagnosticEquipment("1#电池包");
        diagnostic1.setArithmetic("DCIR");
        diagnostic1.setDiagnosticResult("DCIR=0.5Ω");
        diagnostics.add(diagnostic1);

        Diagnostic diagnostic2 = new Diagnostic();
        diagnostic2.setAlarmStatus("2");
        diagnostic2.setThresholdStatus("1");
        diagnostic2.setDiagnosticTime(new Date());
        diagnostic2.setDiagnosticEquipment("1#电池包");
        diagnostic2.setArithmetic("电池电量与容量");
        diagnostic2.setDiagnosticResult("电量=xxxkWh，容量=xxxAh");
        diagnostics.add(diagnostic2);

        pageDto.setRows(diagnostics);
        return pageDto;
    }


    /**
     * 工序列表请求
     *
     * @param model
     */
    @RequestMapping("process_list")
    public void processList(Model model) {

    }

    /**
     * 工序列表数据
     * @param pageNum
     * @param request
     * @return
     */
    @RequestMapping("process_data")
    @ResponseBody
    public PageDto processData(int pageNum, HttpServletRequest request) {

        List<Process> processes = new ArrayList<>();
        Process process1 = new Process();
        process1.setOperate("1");
        process1.setDuration(10);
        processes.add(process1);

        Process process2 = new Process();
        process2.setOperate("2");
        process2.setDuration(9);
        processes.add(process2);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(2L);
        pageDto.setRows(processes);
        return pageDto;
    }

    /**
     * 条件信息请求
     *
     * @param model
     */
    @RequestMapping("condition_info")
    public void conditionInfo(Model model) {

    }

    /**
     * 参数列表数据
     * @param pageNum
     * @param request
     * @return
     */
    @RequestMapping("parameter_data")
    @ResponseBody
    public PageDto parameterData(int pageNum, HttpServletRequest request) {

        List<Parameters> processes = new ArrayList<>();

        Parameters parameters1 = new Parameters();
        parameters1.setCode("C004");
        parameters1.setType("1");
        parameters1.setName("电压");
        processes.add(parameters1);

        Parameters parameters2 = new Parameters();
        parameters2.setCode("B002");
        parameters2.setType("2");
        parameters2.setName("充电过流");
        processes.add(parameters2);

        Parameters parameters3 = new Parameters();
        parameters3.setCode("Z004");
        parameters3.setType("3");
        parameters3.setName("启停开关");
        processes.add(parameters3);

        Parameters parameters4 = new Parameters();
        parameters4.setCode("T006");
        parameters4.setType("4");
        parameters4.setName("供应商");
        processes.add(parameters4);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(4L);
        pageDto.setRows(processes);
        return pageDto;
    }
}